package com.itboye.hutouben.responsitory;

import com.google.gson.reflect.TypeToken;
import com.itboye.hutouben.bean.DingDanQuery;
import com.itboye.hutouben.bean.GoPayBean;
import com.itboye.hutouben.bean.OrderBeans;
import com.itboye.hutouben.bean.OrderDetailBean;
import com.itboye.hutouben.bean.WeiXinPayBean;
import com.itboye.hutouben.interfaces.DingDanInterfaces;
import com.itboye.hutouben.volley.BaseErrorListener;
import com.itboye.hutouben.volley.BaseNetRepository;
import com.itboye.hutouben.volley.BaseSuccessReqListener;
import com.itboye.hutouben.volley.ByJsonRequest;
import com.itboye.hutouben.volley.ICompleteListener;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单
 */
public class DingDanResponsitory extends BaseNetRepository implements DingDanInterfaces<OrderBeans> {
    final String APIKEY = "100";
    public  static  final  String chuangjian="By_Order_create";//订单创建
    public  static  final  String chaxun="By_Order_query";//订单分页查询
    public  static  final  String detail="By_Order_detail";//订单详情
    public  static  final  String lijigoumai="By_Order_createNow";//订单立即购买
    public  static  final  String chongxingoumai="By_Order_repay";//订单重新支付
    public  static  final  String weixinPay="By_Wxpay_prePay";//微信预支付
    public  static  final  String yue="By_Wallet_pay";//余额支付
    public  static  final  String chongzhi="By_Wallet_order";//充值
    public  static  final  String quxiao="By_Repair_unPay";//取消支付
    public  static  final  String deleteZhangHao="By_Wallet_bindDel";//删除绑定的账号
    public  static  final  String cardType="By_Wallet_getBank";//卡号查询银行卡类型

    public DingDanResponsitory(ICompleteListener ICompleteListener){
        super(ICompleteListener);
    }

    /**
     * 订单创建
     * @param s_id          会话id[必须](登陆时保存的auth_login_code)
     * @param uid
     * @param ids           购物车项目id[必须]
     * @param address_id   收货地址id[必须]
     * @param del           删除购物车项标记[可选，默认0 创建订单后不删除购物车项]
     * @param note          备注[可选]
     */
    @Override
    public void generateOrder(String s_id,String uid, String ids, String address_id, String del, String note,String score,String bill_type,String bill_title,String bill_code) {
        Type type = new TypeToken<GoPayBean>() {
        }.getType();
        String apiVer = "101";
        Map<String, Object> map = new HashMap<>();
        map.put("s_id", s_id);
        map.put("uid", uid);
        map.put("ids", ids);
        map.put("address_id", address_id);
        map.put("del", del);
        map.put("note", note);
        map.put("score", score);
        map.put("bill_type", bill_type);
        map.put("bill_title", bill_title);
        map.put("bill_code", bill_code);
        (new ByJsonRequest.Builder<GoPayBean>())
                .setTypeVerParamsAndReturnClass(chuangjian, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<GoPayBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    @Override
    public void generateOrderTwo(String s_id,String uid, String ids, String address_id, String del, String note,String score,String bill_type,String bill_title,String bill_code) {
        Type type = new TypeToken<GoPayBean>() {
        }.getType();
        String apiVer = "101";
        Map<String, Object> map = new HashMap<>();
        map.put("s_id", s_id);
        map.put("uid", uid);
        map.put("ids", ids);
        map.put("address_id", address_id);
        map.put("del", del);
        map.put("note", note);
        map.put("score", score);
        map.put("bill_type", bill_type);
        map.put("bill_title", bill_title);
        map.put("bill_code", bill_code);
        (new ByJsonRequest.Builder<GoPayBean>())
                .setTypeVerParamsAndReturnClass(chuangjian, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<GoPayBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
    /**
     * 订单分页查询
     * @param s_id          会话id[必须](登陆时保存的auth_login_code)
     * @param uid
     * @param keyword       订单关键词（目前和订单包含的商品名称关联）[可选]
     * @param query_status  订单查询状态 [0=>全部,1=>待付款,2=>待发货,3=>待收货,4=>已收货, 7=>已完成 8=>已关闭][可选]
     * @param page_index    页码
     * @param page_size     页大小
     */
    @Override
    public void orderQuery(String s_id,String uid, String keyword, String query_status, String page_index, String page_size) {
        Type type = new TypeToken<DingDanQuery>() {
        }.getType();
        String apiVer = "101";
        Map<String, Object> map = new HashMap<>();
        map.put("s_id", s_id);
        map.put("uid", uid);
        map.put("keyword", keyword);
        map.put("query_status", query_status);
        map.put("page_index", page_index);
        map.put("page_size", page_size);

        (new ByJsonRequest.Builder<DingDanQuery>())
                .setTypeVerParamsAndReturnClass(chaxun, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<DingDanQuery>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 订单详情
     * @param uid
     * @param order_code
     */
    @Override
    public void orderDetail(String uid, String order_code) {
        Type type = new TypeToken<OrderDetailBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("order_code", order_code);

        (new ByJsonRequest.Builder<OrderDetailBean>())
                .setTypeVerParamsAndReturnClass(detail, "101", map, type)
                .requestListener(
                        new BaseSuccessReqListener<OrderDetailBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 订单立即购买
     * @param uid
     * @param sku_pkid      购买的商品的规格id多个逗号分开（注意：不是sku_id）
     * @param count          购买的数量，多个逗号分开（与sku_pkid应该一致）
     * @param address_id    收货地址id[必须]
     * @param note           备注[可选]
     */
    @Override
    public void lijiGouMai(String s_id,String uid, String sku_pkid, String count, String address_id, String note) {
        Type type = new TypeToken<GoPayBean>() {
        }.getType();
        String apiVer = "101";
        Map<String, Object> map = new HashMap<>();
        map.put("s_id", s_id);
        map.put("uid", uid);
        map.put("sku_pkid", sku_pkid);
        map.put("count", count);
        map.put("address_id", address_id);
        map.put("note", note);

        (new ByJsonRequest.Builder<GoPayBean>())
                .setTypeVerParamsAndReturnClass(lijigoumai, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<GoPayBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 订单重新支付
     * @param order_code    订单编号[必须]
     */
    @Override
    public void chongxinGouMai(String s_id,String uid,String order_code) {
        Type type = new TypeToken<GoPayBean>() {
        }.getType();
        String apiVer = "101";
        Map<String, Object> map = new HashMap<>();
        map.put("s_id", s_id);
        map.put("uid", uid);
        map.put("order_code", order_code);

        (new ByJsonRequest.Builder<GoPayBean>())
                .setTypeVerParamsAndReturnClass(chongxingoumai, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<GoPayBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 微信预支付
     * @param pay_code  支付标号
     */
    @Override
    public void WeiXinPay(String pay_code) {
        Type type = new TypeToken<WeiXinPayBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("pay_code", pay_code);

        (new ByJsonRequest.Builder<WeiXinPayBean>())
                .setTypeVerParamsAndReturnClass(weixinPay, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<WeiXinPayBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 充值（获取充值信息）
     * @param uid
     * @param money 充值金额,分,1+
     */
    @Override
    public void chongZhi(String uid, String money) {
        Type type = new TypeToken<GoPayBean>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("money", money);

        (new ByJsonRequest.Builder<GoPayBean>())
                .setTypeVerParamsAndReturnClass(chongzhi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<GoPayBean>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 余额支付
     * @param uid
     * @param pay_code
     */
    @Override
    public void yueZhiFu(String uid, String pay_code) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("pay_code", pay_code);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(yue, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 取消支付
     * @param uid
     * @param id
     */
    @Override
    public void quxiaoZhifu(String uid, String id) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("id", id);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(quxiao, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 删除绑定的账号
     * @param uid
     * @param id
     */
    @Override
    public void deleteZhangHao(String uid, String id) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("uid", uid);
        map.put("id", id);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(deleteZhangHao, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 根据银行卡号查询类型
     * @param bank_no
     */
    @Override
    public void cardLeiXing(String bank_no) {
        Type type = new TypeToken<ArrayList<String>>() {
        }.getType();
        String apiVer = APIKEY;
        Map<String, Object> map = new HashMap<>();
        map.put("bank_no", bank_no);

        (new ByJsonRequest.Builder<ArrayList<String>>())
                .setTypeVerParamsAndReturnClass(cardType, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<ArrayList<String>>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
}
